package com.bdqn.t330.ch10.controller;

import com.bdqn.t330.ch10.entity.SysUser;
import com.bdqn.t330.ch10.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {


    private Logger logger = Logger.getLogger(UserController.class);

    @Autowired
    UserService userService;

    //public String add();
    //public String delete();
    //public String update();

    @RequestMapping("/userList")
    public String userList(Model model) {
        List<SysUser> userList = userService.getUserList();
        model.addAttribute("list", userList);
        return "/user/list";
    }

    @RequestMapping("/userListPage")
    public String userListPage(Model model, Integer pageIndex, Integer pageSize, String userName) {

        if (pageIndex == null) {
            pageIndex = 1;
        }
        if (pageSize == null) {
            pageSize = 5;
        }

        List<SysUser> listPage = userService.getUserListPageBiz(pageIndex, pageSize, userName);
        model.addAttribute("listPage", listPage);
        //回传当前页码
        model.addAttribute("pageIndex", pageIndex);
        model.addAttribute("userName",userName);
        return "/user/listPage";
    }
}
